package com.sanhuo.idms.service;

import com.sanhuo.idms.dao.DormElectricMapper;
import com.sanhuo.idms.entity.DormElectric;
import com.sanhuo.idms.vo.TungComsumeAnalysisVO;
import com.sanhuo.lib.ExceptionUtil;
import com.sanhuo.triild.Basic.BaseMapper;
import com.sanhuo.triild.Basic.BaseService;
import com.sanhuo.triild.annotation.MapperWire;
import com.sanhuo.utils.basic.BeanUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional
public class DormElectricService extends BaseService<DormElectric> {
    @MapperWire
    private DormElectricMapper dormElectricMapper;

    @Override
    public BaseMapper<DormElectric> getBaseMapper() {
        return dormElectricMapper;
    }

    public void update(String dormId, double consume) {
        DormElectric dormElectric = dormElectricMapper.findById(dormId);
        ExceptionUtil.throwException(BeanUtil.isNull(dormElectric), "不存在此宿舍数据");
        dormElectric.setConsume(dormElectric.getConsume() + consume);
        dormElectric.setUpdateTime(new Date());
        update(dormElectric);
    }

    public TungComsumeAnalysisVO anslysisTung(String tungId) {
        return dormElectricMapper.analysisTung(tungId);
    }

}
